﻿package kliment.controls.mediaplayer.core.players {
	import flash.display.DisplayObject;
	import flash.events.EventDispatcher;
	import flash.media.SoundTransform;
	
	import kliment.events.PlayerEvent;
	import kliment.utils.IntervalTimer;
	
	/**
     * Dispatched when .....
     */
    [Event(name = 'laod_open', type = 'kliment.events.PlayerEvent')]
	/**
     * Dispatched when .....
     */
    [Event(name = 'laod_progress', type = 'kliment.events.PlayerEvent')]
	/**
     * Dispatched when .....
     */
    [Event(name = 'laod_complete', type = 'kliment.events.PlayerEvent')]
	/**
     * Dispatched when .....
     */
    [Event(name = 'laod_io_error', type = 'kliment.events.PlayerEvent')]
	/**
     * Dispatched when .....
     */
    [Event(name = 'play_complete', type = 'kliment.events.PlayerEvent')]
	/**
     * Dispatched when .....
     */
    [Event(name = 'play', type = 'kliment.events.PlayerEvent')]
	/**
     * Dispatched when .....
     */
    [Event(name = 'playing', type = 'kliment.events.PlayerEvent')]
	/**
     * Dispatched when .....
     */
    [Event(name = 'pause', type = 'kliment.events.PlayerEvent')]
	/**
     * Dispatched when .....
     */
    [Event(name = 'stop', type = 'kliment.events.PlayerEvent')]
	/**
     * Dispatched when .....
     */
    [Event(name = 'buffering', type = 'kliment.events.PlayerEvent')]
	
	/**
	 * ...
	 * @author	Kliment
	 * @version	1.0.3
	 * 
	 * class name: kliment.controls.mediaplayer.core.players.PlayerAbstract
	 */
	public class AbstractPlayer extends EventDispatcher {
		public const UPDATE_DELAY:Number = 200;
		public const STEP_SECONDS:Number = 2;
		protected var _soundTransform:SoundTransform;
		protected var _url:String;
		protected var _state:String;
		protected var _isLoaded:Boolean = false;
		protected var _pausePosition:Number = 0;
		protected var _bytesTotlal:Number;
		protected var _bytesLoaded:Number;
		protected var _output:DisplayObject;
		protected var _intervalTimer:IntervalTimer;
		
		public function AbstractPlayer() {
			_soundTransform = new SoundTransform();
		}
		
		public function load(url:String):void {
			_pausePosition = 0;
			_isLoaded = false;
			_url = url;
			
		}
		
		public function play():void {			
			_state = PlayerEvent.PLAYING;
			dispatchEvent(new PlayerEvent(PlayerEvent.PLAY));
		}
		
		public function pause():void {
			_state = PlayerEvent.PAUSE;
			dispatchEvent(new PlayerEvent(PlayerEvent.PAUSE));
		}
		
		public function stop():void {
			_state = PlayerEvent.STOP;
			dispatchEvent(new PlayerEvent(PlayerEvent.PLAYING));
			dispatchEvent(new PlayerEvent(PlayerEvent.STOP));
		}
		
		public function forward():void {
			
		}
		
		public function back():void {
			
		}
		
		public function get position():Number { return 0; }
		public function set position(value:Number):void { 
			
		}
		
		public function get soundTransform():SoundTransform { return _soundTransform; }
		public function set soundTransform(value:SoundTransform):void {
			_soundTransform = value;
		}
		
		public function get duration():Number { return 0; }
		
		public function get time():Number { return 0; }
		
		public function get state():String { return _state; }
		
		public function get output():DisplayObject { return _output; }
		
		public function remove():void {
			if (_intervalTimer)
				_intervalTimer.stop();
		}
	}

}